﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using Gumini.JulaDB.Enums;

namespace Gumini.JulaDB.DataTypes
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class NumberDataType : DataType
    {
        public NumberDataType()
            : base(JulaDbType.Number, DbType.Decimal, typeof(decimal)) { }

        public override int Compare(object a, object b)
        {
            return ((decimal)a).CompareTo((decimal)b);
        }

        protected override object ConvertCore(object source)
        {
            var convertible = source as IConvertible;
            return convertible.ToDecimal(CultureInfo.InvariantCulture);
        }

        public override IEnumerable<string> Names
        {
            get { return _names; }
        }
        private List<string> _names = new List<string>() { "int", "integer", "decimal" };

        public override IEnumerable<Type> SourceTypes
        {
            get { return _sourceTypes; }
        }
        private List<Type> _sourceTypes = new List<Type>() { typeof(int), typeof(decimal), typeof(float), typeof(double) };

        public override string ToString()
        {
            return "NUMBER";
        }
    }
}
